package AreaAndLength;

class Trangle{
    double sideA,sideB,sideC,area,length;
    boolean boo;

    public Trangle(double a,double b,double c){
        this.sideA = a;
        this.sideB = b;
        this.sideC = c;
        if(a+b>c && a+c>b && b+c>a ) {
            boo = true;
        } else{
            boo = false;
        }
    }

    double getLength(){
        return sideA+sideB+sideC;
    }

    public double getArea() {
        if (boo) {
            double p = (sideA + sideB + sideC) / 2.0;
            area = Math.sqrt(p*(p-sideA)*(p-sideB)*(p-sideC));
            return area;
        } else{
            System.out.println("不是一个三角形，不能计算面积");
            return 0;
        }
    }

    public void setABC(double a,double b,double c){
        this.sideA = a;
        this.sideB = b;
        this.sideC = c;
        if(a+b>c && a+c>b && b+c>a ) {
            boo = true;
        } else{
            boo = false;
        }
    }

}

class Lader{
    double above,bottom,height,area;
    Lader(double a,double b,double h){
        this.above = a;
        this.bottom = b;
        this.height = h;
    }

    double getArea(){
        area = (above + bottom) / 2 * height;
        return area;
    }
}

public class AreaAndLength {
    public static void main(String[] args) {
        double length,area;
        Trangle trangle;
        Lader lader;
        trangle = new Trangle(3,4,5);
        lader = new Lader(3,4,10);
        length = trangle.getLength();
        System.out.println("三角形的周长:"+length);
        area = trangle.getArea();
        System.out.println("三角形的面积:"+area);
        area = lader.getArea();
        System.out.println("梯形的面积:"+area);
        trangle.setABC(12,34,1);
        area = trangle.getArea();
        System.out.println("三角形的面积:"+area);
        length = trangle.getLength();
        System.out.println("三角形的周长:"+length);
    }
}
